package pwd.allen.export.easyexcel.writeHandler;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import com.alibaba.excel.write.property.ExcelWriteHeadProperty;

import java.util.Map;

/**
 * @author lenovo
 * @create 2020-06-16 17:13
 **/
public class MySheetWriteHandler implements SheetWriteHandler {
    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

        // 改变列顺序，把第3列放到第6列去
        ExcelWriteHeadProperty excelWriteHeadProperty = writeSheetHolder.getExcelWriteHeadProperty();
        Map<Integer, Head> headMap = excelWriteHeadProperty.getHeadMap();
        Map<Integer, ExcelContentProperty> contentPropertyMap = excelWriteHeadProperty.getContentPropertyMap();
        headMap.put(5, headMap.get(2));
        headMap.remove(2);

        contentPropertyMap.put(5, contentPropertyMap.get(2));
        contentPropertyMap.remove(2);
    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
    }
}
